package com.education.basic.action;

import com.education.basic.entity.Administrator;
import com.education.basic.entity.FeeInfo;
import com.education.basic.exception.AuthorityException;
import com.education.basic.service.FeeInfoService;
import com.yunshangwoniu.core.baseAction.BaseAction;
import com.yunshangwoniu.core.cache.CacheAble;
import com.yunshangwoniu.core.page.Page;
import com.yunshangwoniu.core.utils.RequestUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@Controller
@Scope("prototype")
@Namespace("/feeInfo")
@ParentPackage(value="struts-default")
public class FeeInfoAction extends BaseAction
{

    /**
	 * 
	 */
	private static final long serialVersionUID = -3216102374122417822L;
	@Autowired
    private FeeInfoService feeInfoService;
    @Autowired
    private CacheAble<Object, Object> cacheAble;
    private Integer pageNo;
    private Page<FeeInfo> page;
    private boolean isFee;
    private String stuNo;
    private String name;

	@Action(value="list",results={@Result(name="success",location="list.jsp"), @Result(name = "authority",
            location = "/authority.html")})
	public String list()
	{
        Administrator ad = (Administrator) cacheAble.get(RequestUtils.getIp(getRequest()));
        if(ad==null||(ad!=null&&ad.getLevel()==4))
        {
            return  "authority";
        }
        pageNo = pageNo==null?1:pageNo;
        Map<String,Object> params = new HashMap<String, Object>();
        params.put("isFee",isFee);
        page = feeInfoService.queryFeeInfo(params,pageNo, 10, getRequest());
		return "success";
	}

    @Action(value="pay")
    public void pay() throws Exception
    {
        feeInfoService.pay(stuNo);
        PrintWriter pw = getResponse().getWriter();
        pw.print("success");
        pw.flush();
        pw.close();
    }

    @Action(value="search",results={@Result(name="success",location="list.jsp")})
    public String search()
    {
        pageNo = pageNo==null?1:pageNo;
        Map<String,Object> params = new HashMap<String, Object>();
       // params.put("isFee",isFee);
        params.put("studentName",name);
        page = feeInfoService.queryFeeInfo(params,pageNo, 10, getRequest());
        return "success";
    }

    public FeeInfoService getFeeInfoService() {
        return feeInfoService;
    }

    public void setFeeInfoService(FeeInfoService feeInfoService) {
        this.feeInfoService = feeInfoService;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Page<FeeInfo> getPage() {
        return page;
    }

    public void setPage(Page<FeeInfo> page) {
        this.page = page;
    }

    public boolean isIsFee() {
        return isFee;
    }

    public void setIsFee(boolean isFee) {
        this.isFee = isFee;
    }

    public String getStuNo() {
        return stuNo;
    }

    public void setStuNo(String stuNo) {
        this.stuNo = stuNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

	public CacheAble<Object, Object> getCacheAble()
	{
		return cacheAble;
	}

	public void setCacheAble(CacheAble<Object, Object> cacheAble)
	{
		this.cacheAble = cacheAble;
	}

    
}
